import { defineConfig, loadEnv } from 'vite';
import solidPlugin from 'vite-plugin-solid';
// import devtools from 'solid-devtools/vite';

const AppBase = (mode: string, envDir: string) => {
  const appBase = loadEnv(mode, envDir).VITE_APP_NAME
  return appBase?.trim() === '' ? '' : `/${appBase}`;
}

export default ({ mode }: { mode: string }) => defineConfig({
  plugins: [
    /* 
    Uncomment the following line to enable solid-devtools.
    For more info see https://github.com/thetarnav/solid-devtools/tree/main/packages/extension#readme
    */
    // devtools(),
    solidPlugin(),
  ],
  base: AppBase(mode, process.cwd()),
  server: {
    port: 3000,
  },
  build: {
    target: 'esnext',
  },
});
